Conda

miniconda is a light version of anaconda, it contains only Conda, Python and other necessary tools. miniforge is similar to minicoda but conda-forge is the only channel by default. miniconda has package installer while miniforge has only command installer.

Use conda-forge channel instead of defaults channel when installing packages and use pip only when conda doesn't have certain packages.

Install conda

First, download miniconda package installer and install it.

Second, configure conda in file .zshrc (a place for personal configurations):

  • Open .zshrc in terminal vim ~/.zshrc,
  • Type i to open edit mode (--INSERT-- will appear at bottom),
  • Write export PATH=/path/to/miniconda3/bin:$PATH in a new line,
  • Press esc to close edit mode,
  • Move the cursor to end and type : (: will appear at bottom), type wq (add ! if there is read only problem) after : and press enter to close .zshrc,
  • Make configurations effective source ~/.zshrc.

Third, set conda-forge as the only channel:

  • Add conda-forge channel conda config --add channels conda-forge,
  • Remove defaults channel conda config --remove channels defaults,
  • Update all packages in base environment with conda-forge channel conda update --all.

If using Mac and xcrun error occurs, use xcode-select --install.

Conda commands

conda --version
conda list

conda search --full-name pkg_precise
conda search pkg_pattern

conda install pkg=version
conda uninstall pkg

conda update conda
conda update pkg=version
conda update --all

conda create --name env python=version
conda create --name env1 --clone env2
conda activate env
conda deactivate
conda env list
conda env remove --name env

conda config --get channels
conda config --add channels channel
conda config --set channel_priority strict
conda config --remove channels channel

Pip

Install pip

pip comes with conda environments.

To solve spuare brackets no matches found issue when using pip:

  • Open .zshrc in terminal vim ~/.zshrc,
  • Type i to open edit mode (--INSERT-- will appear at bottom),
  • Write setopt no_nomatch in a new line,
  • Press esc to close edit mode,
  • Move the cursor to end and type : (: will appear at bottom), type wq (add ! if there is readonly problem) after : and press enter to close .zshrc,
  • Make configurations effective source ~/.zshrc.

Pip commands

pip --version
pip list
pip list --outdated

pip check pkg
pip check

pip install pkg==version
pip install --upgrade pip
pip install --upgrade pkg==version
pip uninstall pkg

pip freeze
pip freeze > requirements.txt
pip install -r requirements.txt

Environments

Using Jupyter notebook in VSCode doesn't require official Jupyter installed but these packages are needed:

  • ipykernel converts conda environments into kernels
  • nbconvert and pretty-jupyter export Jupyter notebooks into htmls

Create data environment in base environment:

conda create --name data ipykernel \
    python python-docx pandas openpyxl ydata-profiling \
    scikit-learn py-xgboost lightgbm catboost optuna \
    langchain openai transformers \
    plotly nbconvert

pip install pretty-jupyter

To activate data environment and enter into Projects directory when launching terminal:

  • Open .zshrc in terminal vim ~/.zshrc,
  • Type i to open edit mode (--INSERT-- will appear at bottom),
  • Write conda activate data and cd /path/to/Projects in separated new lines,
  • Press esc to close edit mode,
  • Move the cursor to end and type : (: will appear at bottom), type wq (add ! if there is readonly problem) after : and press enter to close .zshrc,
  • Make configurations effective source ~/.zshrc.

Git

Use SSH rather than https for fast and stable connection from local to remote.

Set up SSH (step 1):

  • Launch terminal and go to home directory cd ~,
  • Generate an SSH key pair ssh-keygen -t ed25519 -C "user-email",
  • Press enter to confirm default directory path,
  • Choose your passphrase.

Set up Gitee:

  • Run cat ~/.ssh/id_ed25519.pub, use the contents as new SSH key on Gitee and use studio as SSH key title,
  • Authenticate SSH for Git git config --global user.name "gitee-user-name" and git config --global user.email "gitee-user-email",
  • Go to Projects directory cd /path/to/Projects/, clone Gitee repository to local git clone git@gitee.com:gitee-user-name/repository, enter yes to confirm connection and enter your passphrase to continue,
  • Test SSH connection from local to Gitee ssh -T git@gitee.com.

Set up GitHub:

  • Run cat ~/.ssh/id_ed25519.pub, use the contents as new SSH key on GitHub and use studio as SSH key title,
  • Authenticate SSH for Git git config --global user.name "github-user-name" and git config --global user.email "github-user-email",
  • Go to Projects directory cd /path/to/Projects/, clone GitHub repository to local git clone git@github.com:github-user-name/repository, enter yes to confirm connection and enter your passphrase to continue,
  • Test SSH connection from local to GitHub ssh -T git@github.com.

Set up SSH (step 2):

  • Ensure correct SSH key file permissions chmod 600 ~/.ssh/id_ed25519.pub,
  • Add SSH key to SSH agent ssh-add ~/.ssh/id_ed25519.